﻿using ASmile.Setter.DaBLL;
using ASmile.Win;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ASmile.Setter
{
    public partial class FrmLogin : FrmBaseModal
    {
        public FrmLogin()
        {
            InitializeComponent();
        }

        LoginBLL BLLObj { get; } = new LoginBLL();


        int LogErrCount = 0;

        private void FrmLogin_Load(object sender, EventArgs e)
        {

        }

        private void txtLoginName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtLoginPwd.Focus();
            }
        }


        private void txtLoginPwd_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnOK.Focus();
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            var ret = BLLObj.Login(txtLoginName.Text, txtLoginPwd.Text);
            if (!ret)
            {
                LogErrCount++;
                ShowMessage(ret.msg);
                if (LogErrCount > 3)
                {
                    MessageBox.Show("登陆失败超过3次");
                    this.Close();
                }
                return;
            }
            this.DialogResult = DialogResult.OK;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}